home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1990 / 05 / wmisc.asm < prev    next >
Assembly Source File  |  1990-07-06  |  2KB  |  82 lines

  1.     title    miscellaneous procedures
  2.     include    asm.inc
  3.  
  4.     .code
  5.     extn    malloc_raw
  6.     public    calloc_read,save_most
  7.  
  8.  
  9. ;;    calloc raw
  10. ;
  11. ;    entry    CX    request bytes size (0<x<0FFF0h)
  12. ;    exit    ES:DI    storage bucket pointer
  13. ;        Cf    if not enough memory or request too large
  14. ;    uses    AX
  15. ;
  16. calloc_raw proc
  17.     call    malloc_raw
  18.     jc    car1
  19.     pushm    cx,di
  20.     mov    al,0
  21.     rep    stosb
  22.     popm    di,cx
  23. car1:    ret
  24. calloc_raw endp
  25.  
  26.  
  27. ;;    calloc read
  28. ;
  29. ;    entry    CX    requested byte count
  30. ;    exit    DS:SI    pointer to zeroed storage bucket
  31. ;        Cf    if no storage
  32. ;    uses    AX
  33. ;
  34. calloc_read proc
  35.     pushm    di,es
  36.     call    calloc_raw
  37.     jc    cal1
  38.     push    es
  39.     pop    ds
  40.     mov    si,di
  41. cal1:    popm    es,di
  42.     ret
  43. calloc_read endp
  44.  
  45.  
  46. ;;    restore most
  47. ;
  48. ;    note    never call this routine
  49. ;
  50. restore_most proc
  51.     popm    bp,es,ds,si,di,dx,cx,bx
  52.     ret
  53. restore_most endp
  54.  
  55.  
  56. ;;    save most
  57. ;
  58. ;    note    saves all registers except AX and BP.  however, the current
  59. ;        version also saves BP because the code works out that way.
  60. ;        the registers are automatically restored.  this routine is
  61. ;        called with a return address as the top of stack.
  62. ;
  63. save_most proc                ; +16 inner ret adr, +18 outer ret adr
  64.     push    cx            ; +14
  65.     push    dx            ; +12
  66.     push    di            ; +10
  67.     push    si            ; +8
  68.     push    ds            ; +6
  69.     push    es            ; +4
  70.     push    bp            ; +2
  71.     lea    bp,restore_most        ;     after execution of inner
  72.     push    bp            ; +0  routine, return to restore_most
  73.     mov    bp,sp
  74.     xchg    bx,[bp+16]        ;    bx above cx
  75.     push    bx            ; -2    setup return to inner routine
  76.     mov    bx,[bp+16]        ;    restore original BX and BP
  77.     mov    bp,[bp+2]
  78.     ret
  79. save_most endp
  80.  
  81.     end
  82.